package com.baibei.ebec.widget;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * 碎片管理器，禁止viewPager滚动来管理碎片
 * Created by shenminjie on 2017/8/2 13:45.
 * mail:shenminjie@100bei.com
 */

public class FragmentContainer extends ViewPager {
    /**
     * 默认禁止滑动
     */
    private boolean isPagingEnabled = false;

    public FragmentContainer(Context context) {
        super(context);
    }

    public FragmentContainer(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        return this.isPagingEnabled && super.onTouchEvent(event);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {
        return this.isPagingEnabled && super.onInterceptTouchEvent(event);
    }

    public void setPagingEnabled(boolean canScroll) {
        this.isPagingEnabled = canScroll;
    }
}
